function _typeof(t) {
    return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
        return typeof t;
    } : function(t) {
        return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
    })(t);
}

!function(t, e) {
    "object" === ("undefined" == typeof exports ? "undefined" : _typeof(exports)) && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : (void 0).ES6Promise = e();
}(0, function() {
    function a(t) {
        return "function" == typeof t;
    }
    function e() {
        var t = setTimeout;
        return function() {
            return t(r, 1);
        };
    }
    function r() {
        for (var t = 0; t < j; t += 2) {
            (0, Y[t])(Y[t + 1]), Y[t] = void 0, Y[t + 1] = void 0;
        }
        j = 0;
    }
    function u(t, e) {
        var r = arguments, n = this, o = new this.constructor(f);
        void 0 === o[F] && m(o);
        var i, s = n._state;
        return s ? (i = r[s - 1], x(function() {
            return v(s, o, i, n._result);
        })) : _(n, o, t, e), o;
    }
    function c(t) {
        if (t && "object" === _typeof(t) && t.constructor === this) return t;
        var e = new this(f);
        return h(e, t), e;
    }
    function f() {}
    function s(t) {
        try {
            return t.then;
        } catch (t) {
            return N.error = t, N;
        }
    }
    function l(t, e, r) {
        var n, o, i, s;
        e.constructor === t.constructor && r === u && e.constructor.resolve === c ? (i = t, 
        (s = e)._state === K ? p(i, s._result) : s._state === L ? d(i, s._result) : _(s, void 0, function(t) {
            return h(i, t);
        }, function(t) {
            return d(i, t);
        })) : r === N ? (d(t, N.error), N.error = null) : void 0 === r ? p(t, e) : a(r) ? (n = e, 
        o = r, x(function(e) {
            var r = !1, t = function(t, e, r, n) {
                try {
                    t.call(e, r, n);
                } catch (t) {
                    return t;
                }
            }(o, n, function(t) {
                r || (r = !0, n !== t ? h(e, t) : p(e, t));
            }, function(t) {
                r || (r = !0, d(e, t));
            }, e._label);
            !r && t && (r = !0, d(e, t));
        }, t)) : p(t, e);
    }
    function h(t, e) {
        var r, n;
        t === e ? d(t, new TypeError("You cannot resolve a promise with itself")) : (n = _typeof(r = e), 
        null === r || "object" !== n && "function" !== n ? p(t, e) : l(t, e, s(e)));
    }
    function n(t) {
        t._onerror && t._onerror(t._result), y(t);
    }
    function p(t, e) {
        t._state === D && (t._result = e, t._state = K, 0 !== t._subscribers.length && x(y, t));
    }
    function d(t, e) {
        t._state === D && (t._state = L, t._result = e, x(n, t));
    }
    function _(t, e, r, n) {
        var o = t._subscribers, i = o.length;
        t._onerror = null, o[i] = e, o[i + K] = r, o[i + L] = n, 0 === i && t._state && x(y, t);
    }
    function y(t) {
        var e = t._subscribers, r = t._state;
        if (0 !== e.length) {
            for (var n = void 0, o = void 0, i = t._result, s = 0; s < e.length; s += 3) n = e[s], 
            o = e[s + r], n ? v(r, n, o, i) : o(i);
            t._subscribers.length = 0;
        }
    }
    function t() {
        this.error = null;
    }
    function v(t, e, r, n) {
        var o = a(r), i = void 0, s = void 0, u = void 0, c = void 0;
        if (o) {
            if ((i = function(e, t, r) {
                try {
                    return e(t);
                } catch (t) {
                    return getApp().onError("api.catch: " + t.stack + "---" + e.toString() + "---" + (r._result || "").toString()), 
                    console.error("promise catch:", t, e, (r._result || "").toString()), U.error = t, 
                    U;
                }
            }(r, n, t)) === U ? (c = !0, s = i.error, i.error = null) : u = !0, e === i) return void d(e, new TypeError("A promises callback cannot return that same promise."));
        } else i = n, u = !0;
        e._state !== D || (o && u ? h(e, i) : c ? d(e, s) : t === K ? p(e, i) : t === L && d(e, i));
    }
    function m(t) {
        t[F] = W++, t._state = void 0, t._result = void 0, t._subscribers = [];
    }
    function o(t, e) {
        this._instanceConstructor = t, this.promise = new t(f), this.promise[F] || m(this.promise), 
        S(e) ? (this.length = e.length, this._remaining = e.length, this._result = new Array(this.length), 
        0 === this.length ? p(this.promise, this._result) : (this.length = this.length || 0, 
        this._enumerate(e), 0 === this._remaining && p(this.promise, this._result))) : d(this.promise, new Error("Array Methods must be provided an Array"));
    }
    function b(t) {
        this[F] = W++, this._result = this._state = void 0, this._subscribers = [], f !== t && ("function" != typeof t && function() {
            throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");
        }(), this instanceof b ? function(e, t) {
            try {
                t(function(t) {
                    h(e, t);
                }, function(t) {
                    d(e, t);
                });
            } catch (t) {
                d(e, t);
            }
        }(this, t) : function() {
            throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
        }());
    }
    var i, g, w, A, S = Array.isArray ? Array.isArray : function(t) {
        return "[object Array]" === Object.prototype.toString.call(t);
    }, j = 0, E = void 0, T = void 0, x = function(t, e) {
        Y[j] = t, Y[j + 1] = e, 2 === (j += 2) && (T ? T(r) : q());
    }, M = "undefined" != typeof window ? window : void 0, P = M || {}, C = P.MutationObserver || P.WebKitMutationObserver, O = "undefined" == typeof self && "undefined" != typeof process && "[object process]" === {}.toString.call(process), k = "undefined" != typeof Uint8ClampedArray && "undefined" != typeof importScripts && "undefined" != typeof MessageChannel, Y = new Array(1e3), q = void 0;
    q = O ? function() {
        return process.nextTick(r);
    } : C ? (g = 0, w = new C(r), A = document.createTextNode(""), w.observe(A, {
        characterData: !0
    }), function() {
        A.data = g = ++g % 2;
    }) : k ? ((i = new MessageChannel()).port1.onmessage = r, function() {
        return i.port2.postMessage(0);
    }) : void 0 === M && "function" == typeof require ? function() {
        try {
            var t = require("vertx");
            return void 0 !== (E = t.runOnLoop || t.runOnContext) ? function() {
                E(r);
            } : e();
        } catch (t) {
            return e();
        }
    }() : e();
    var F = Math.random().toString(36).substring(16), D = void 0, K = 1, L = 2, N = new t(), U = new t(), W = 0;
    return o.prototype._enumerate = function(t) {
        for (var e = 0; this._state === D && e < t.length; e++) this._eachEntry(t[e], e);
    }, o.prototype._eachEntry = function(e, t) {
        var r = this._instanceConstructor, n = r.resolve;
        if (n === c) {
            var o = s(e);
            if (o === u && e._state !== D) this._settledAt(e._state, t, e._result); else if ("function" != typeof o) this._remaining--, 
            this._result[t] = e; else if (r === b) {
                var i = new r(f);
                l(i, e, o), this._willSettleAt(i, t);
            } else this._willSettleAt(new r(function(t) {
                return t(e);
            }), t);
        } else this._willSettleAt(n(e), t);
    }, o.prototype._settledAt = function(t, e, r) {
        var n = this.promise;
        n._state === D && (this._remaining--, t === L ? d(n, r) : this._result[e] = r), 
        0 === this._remaining && p(n, this._result);
    }, o.prototype._willSettleAt = function(t, e) {
        var r = this;
        _(t, void 0, function(t) {
            return r._settledAt(K, e, t);
        }, function(t) {
            return r._settledAt(L, e, t);
        });
    }, b.all = function(t) {
        return new o(this, t).promise;
    }, b.race = function(o) {
        var i = this;
        return new i(S(o) ? function(t, e) {
            for (var r = o.length, n = 0; n < r; n++) i.resolve(o[n]).then(t, e);
        } : function(t, e) {
            return e(new TypeError("You must pass an array to race."));
        });
    }, b.resolve = c, b.reject = function(t) {
        var e = new this(f);
        return d(e, t), e;
    }, b._setScheduler = function(t) {
        T = t;
    }, b._setAsap = function(t) {
        x = t;
    }, b._asap = x, b.prototype = {
        constructor: b,
        then: u,
        catch: function(t) {
            return this.then(null, t);
        }
    }, b.polyfill = function() {
        var t = void 0;
        if ("undefined" != typeof global) t = global; else if ("undefined" != typeof self) t = self; else try {
            t = Function("return this")();
        } catch (t) {
            throw new Error("polyfill failed because global object is unavailable in this environment");
        }
        var e = t.Promise;
        if (e) {
            var r = null;
            try {
                r = Object.prototype.toString.call(e.resolve());
            } catch (t) {}
            if ("[object Promise]" === r && !e.cast) return;
        }
        t.Promise = b;
    }, b.Promise = b;
});